let brain = require("brain.js");
let json = require("./model.json");
let data = require("../res/res.json");

let network = new brain.NeuralNetwork();
network.fromJSON(json);

function aiyc(n = 2) {
  let keys = Object.keys(data);

  const output = network.run(data[keys[keys.length - n]].wzjred);
  let res = output.map((x) => Math.round(x * 100)).sort((a, b) => a - b);
  console.log(keys[keys.length - 1] + "红球结果--->", res);
  return res;
}

for (let item in data) {
  let o = item - 0 + 1;
  if (data[o] && item >= 2025005 && item <= 2025015) {
    // if (data[o] && item >= 2024110) {
    const output = network.run(data[item].wzjred);
    console.log(
      o + "预测红球结果--->",
      output.map((x) => Math.round(x * 100)).sort((a, b) => a - b),
      "真实结果--->",
      data[o].red
    );
  }
}

aiyc();
module.exports = aiyc;
